package com.example.excelimporter.controller;

import com.example.excelimporter.model.ImportResult;
import com.example.excelimporter.service.ExcelImportService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/excel-import")
public class ExcelImportController {

    @Autowired
    private ExcelImportService excelImportService;

    @PostMapping("/{templateId}")
    public ImportResult importExcel(
            @PathVariable String templateId,
            @RequestParam("file") MultipartFile file) {
        try {
            return excelImportService.importExcel(file, templateId);
        } catch (Exception e) {
            ImportResult result = new ImportResult();
            result.setErrorMessage(e.getMessage());
            return result;
        }
    }
}
